﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.d00_hdaMenu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void d00_hda_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            d00_hdaMgr mgr = new d00_hdaMgr();
            e.Total = int.Parse(mgr.GetRecordCount_d00_hda(e.Parameters[d00_hda_Filter.ParamPrefix]));
            IList<d00_hda> list = mgr.FindAllByPage_d00_hda(e.Start.ToString(), e.Limit.ToString(), e.Parameters[d00_hda_Filter.ParamPrefix]);
            d00_hda_MainStore.DataSource = list;
            d00_hda_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            d00_hdaMgr mgr = new d00_hdaMgr();
            RowSelectionModel sm = d00_hda_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                d00_hda _d00_hda = new d00_hda();
                _d00_hda.jtbm = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_d00_hda(_d00_hda))
                {
                    log.Debug("d00_hda中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            d00_hda_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            d00_hdaMgr mgr = new d00_hdaMgr();
            d00_hda _d00_hda = new d00_hda();
            if (Hid.Text.Length > 0)
                _d00_hda = mgr.FindById_d00_hda(int.Parse(Hid.Text));
            
			_d00_hda.dzbm = Txtdzbm.Text.Trim();
			_d00_hda.hbh = Txthbh.Text.Trim();
			_d00_hda.rbh = Txtrbh.Text.Trim();
			_d00_hda.hzxm = Txthzxm.Text.Trim();
			_d00_hda.hzxb = Txthzxb.Text.Trim();
			_d00_hda.sfzh = Txtsfzh.Text.Trim();
			_d00_hda.zbh = Txtzbh.Text.Trim();
			_d00_hda.cbh = Txtcbh.Text.Trim();
			_d00_hda.txdz = Txttxdz.Text.Trim();
			_d00_hda.yzbm = Txtyzbm.Text.Trim();
			_d00_hda.dhhm = Txtdhhm.Text.Trim();
			_d00_hda.dzyx = Txtdzyx.Text.Trim();
			_d00_hda.jtrs = Txtjtrs.Text.Trim();
			_d00_hda.nyrs = int.Parse(TxtNumnyrs.Text.Trim());
			_d00_hda.ssdq = Txtssdq.Text.Trim();
			_d00_hda.chsx = Txtchsx.Text.Trim();
			_d00_hda.hsx = Txthsx.Text.Trim();
			_d00_hda.jzjb = Txtjzjb.Text.Trim();
			_d00_hda.rcbz = Txtrcbz.Text.Trim();
			_d00_hda.rcsj = Txtrcsj.Text.Trim();
			_d00_hda.rcyy = Txtrcyy.Text.Trim();
			_d00_hda.jhje = Txtjhje.Text.Trim();
			_d00_hda.syje = Txtsyje.Text.Trim();
			_d00_hda.hbz = int.Parse(TxtNumhbz.Text.Trim());
			_d00_hda.jdsj = Txtjdsj.Text.Trim();
			_d00_hda.dybz = Txtdybz.Text.Trim();
			_d00_hda.hdbz = Txthdbz.Text.Trim();
			_d00_hda.ylzh = Txtylzh.Text.Trim();
			_d00_hda.fzbz = Txtfzbz.Text.Trim();
			_d00_hda.yhkh = Txtyhkh.Text.Trim();
			_d00_hda.yhxm = Txtyhxm.Text.Trim();
			_d00_hda.yhzt = Txtyhzt.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_d00_hda(_d00_hda);
            else
                isok = mgr.Add_d00_hda(_d00_hda);
            if (isok)
            {
                d00_hda_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("d00_hda中执行了保存（插入或修改），并成功");
                d00_hda_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}